<?php

namespace app\service;

class MenuService extends BaseService
{
    protected $field = ['*'];

    protected $menu_id = 0;

    public function get($model)
    {
       return $this->setMenu(parent::get($model));
    }

    public function setMenu($data)
    {
        $data = collection($data)->toArray();
        $info = $data;
        foreach ($data as $index => $item){
            $menu = [];
            foreach ($info as $k =>$v){
                if($item['id'] == $v['menu_id']){
                    $menu[] = $v;
                }
            }
            $data[$index]['action'] = $menu;
            if($item['menu_id'] > $this->menu_id){
                unset($data[$index]);
            }
        }
        return $data;
    }


}